﻿using System;
using System.Data.Common;

namespace SimpleOrmCFPC.Apis.Db.Sqlite
{
    public class SQLiteReader : ISQLReader
    {
        private readonly DbDataReader reader;

        public SQLiteReader(DbDataReader reader)
        {
            this.reader = reader;
        }

        public object Read(string key, Type type)
        {
            var value = reader[key];
            if (type.IsEnum)
                value = Enum.ToObject(type, (Int64) value);
            if (value is System.DBNull)
                return null;
            return Convert.ChangeType(value, type, null);
        }

        public bool Next()
        {
            return reader.Read();
        }
    }
}